//
//  UIButton+Extension.swift
//  微博个人swift
//
//  Created by 李灏 on 16/2/16.
//  Copyright © 2016年 lh. All rights reserved.
//

import UIKit

extension UIButton {
    //背景图加图片
    convenience init(backImageName: String?,imageName: String?) {
        self.init()
        if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            //设置高亮
            setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
        
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
            setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
        }
        //大小自适应
        sizeToFit()
    }
    //背景图加文案
    convenience init(backImageName: String?,title: String,textColor: UIColor,imageName: String? = nil,fontSize: CGFloat = 14) {
        self.init()
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        
        if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
        
        sizeToFit()
    }
}
